package com.woniuxy.hrm.producer;

import com.woniuxy.hrm.util.RabbitmqConst;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DelayProducer {
    @Autowired
    RabbitTemplate rabbitTemplate;
    public void sendDelay(String routingKey, String message,Integer ttl){
        rabbitTemplate.convertAndSend(RabbitmqConst.DELAY_EXCHANGE,routingKey, message, new MessagePostProcessor() {

                    @Override
                    public Message postProcessMessage(Message message) throws AmqpException {
                        message.getMessageProperties().setDelay(ttl);
                        return message;
                    }
                }

        );

    }
}
